package com.gxa.modules.sys.controller;

import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.sys.dto.DoorDto;
import com.gxa.modules.sys.entity.Door;
import com.gxa.modules.sys.service.DoorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Api(tags = "大门管理接口")
@RestController
public class DoorController {

    @Autowired
    private DoorService doorService;

    @ApiOperation(value = "大门管理查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "manner",value ="查询条件",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "startDate",value ="查询条件",dataType ="Date"),
            @ApiImplicitParam(paramType = "query",name = "endDate",value ="查询条件",dataType ="Date"),
            @ApiImplicitParam(paramType = "query",name = "order",value ="升序asc，降序填desc",dataType ="String"),
            @ApiImplicitParam(paramType = "query",name = "sidx",value ="排序字段",dataType ="String"),

    })
    @GetMapping("/door/query")
    public Result<PageUtils> queryAll(@RequestParam @ApiIgnore Map<String,Object> params){
        try {
            PageUtils pageUtils = this.doorService.queryByPage(params);
            return new Result().ok(pageUtils);
        } catch (Exception e) {
            return new Result().error("查询失败");
        }
    }

    @ApiOperation(value = "添加开门接口")
    @PostMapping("/Door/add")
    public Result addDoor(@RequestBody DoorDto doorDto){
        try {
            Date date = new Date(System.currentTimeMillis());
            doorDto.setOpenTime(date);
            this.doorService.addDoor(doorDto);
            return new Result().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new Result().error("添加失败");
        }
    }


}
